/**
 * 查看代码 展开收缩
 */
!function () {
    $('.J_Demo').each(function () {
        var $this = $(this);
        var h = $this.find('.J_DemoContent').height();
        var $code = $this.find('.J_DemoCode');

        if (h >= $code.find('pre').height() + 5) {
            $this.find('.J_DemoToggle').hide();
        }

        $code.css('height', h).data('height', h);

        $this.find('.J_DemoToggle').on('click', function () {
            if ($code.data('height') == 'auto') {
                $code.data('height', h).css({'height': h});
            } else {
                $code.data('height', 'auto').css({'height': 'auto'});
            }
            $(this).toggleClass('down');
        });
    });
}();

!function () {
    $('#J_Icons').find('.grids-item').on('click', function () {
        var $this = $(this);
        var str = '<i class="' + $this.find('.grids-icon').find('i').attr('class') + '"></i>';
        const save = function (e) {
            e.clipboardData.setData('text/plain', str);
            e.preventDefault();
        };
        document.addEventListener('copy', save);
        document.execCommand('copy');
        document.removeEventListener('copy', save);

        YDUI.dialog.toast('组件代码已经复制到剪贴板', 'none', 1500);
    });
}();

!function () {
    if (/firefox/.test(navigator.userAgent.toLowerCase()) || !!window.ActiveXObject || "ActiveXObject" in window) {
        YDUI.dialog.alert('请使用谷歌内核浏览器访问本页面');
    }

    setTimeout(function () {
        $(".duoshuo").fadeIn();
    }, 388);

    // 渐隐导航
    setTimeout(function () {
        $("#J_NavMask").hide();
    }, 88);
}();

!function ($, window) {

    var f = $(window).height();
    $("#J_Nav").find("dd").each(function () {
        var c = $(this);
        if (c.find("a").attr("href") == location.pathname)return f / 1.5 < c.offset().top && $("#J_Nav").animate({scrollTop: c.offset().top - f + 888}, 0), c.addClass("cur")
    });

    var $backtop = $("#J_BackTop");
    $("#J_Content").on("scroll", function () {
        300 < $(this).scrollTop() ? $backtop.addClass("show") : $backtop.removeClass("show");
    });
    $backtop.on("click", function () {
        var c = $(this);
        $("#J_Content").animate({scrollTop: 0}, function () {
            c.removeClass("show")
        });
    });
}(jQuery, window);